package com.mapper;


import com.pojo.SalesOrderDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 销售订单细节映射器
 *
 * @author admin
 * @date 2023/06/20
 */
@Mapper
public interface SalesOrderDetailMapper {
    /**
     * 添加销售订单
     *
     * @return int
     */
    //添加销售订单明细表
    @Insert("INSERT INTO sales_order_detail VALUES" +
            " (default," +
            "#{salesOrderNo}," +
            "#{salesOrderId}," +
            "#{productId}," +
            "#{productName}," +
            "#{productQuantity}," +
            "#{productPrice}," +
            "#{totalPrice}," +
            "#{salesDate}," +
            "#{sizeId}," +
            "#{state})")
    int addSalesOrder(SalesOrderDetail salesOrderDetail);

    /**
     * 查询价格
     *
     * @param productId 产品标识
     * @param sizeId    尺寸标识
     * @return {@link Double}
     *///根据产品id和型号id查询价格
    @Select("select price from product_size_specification_price_rel where product_id = #{param1} and size_id = #{param2};")
    Double queryPrice(Integer productId, Integer sizeId);

    /**
     * 查询销售订单明细
     *
     * @param salesOrderId 销售订单id
     * @return {@link List}<{@link SalesOrderDetail}>
     */
    @Select("        select sales_order_detail_id salesOrderDetailId,\n" +
            "        sales_order_no salesOrderNo,\n" +
            "        sales_order_id salesOrderId,\n" +
            "        product_id productId,\n" +
            "        product_name productName,\n" +
            "        product_quantity productQuantity,\n" +
            "        product_price productPrice,\n" +
            "        total_price totalPrice,\n" +
            "        sales_date salesDate,\n" +
            "        size_id sizeId,\n" +
            "        state state\n" +
            "        from sales_order_detail\n" +
            "        where sales_order_id = #{salesOrderDetailId}")
    List<SalesOrderDetail> QuerySalesOrderDetail(Long salesOrderId);

    int addSalesOrderDetails(List<SalesOrderDetail> orderDetails);

    @Update("update sales_order_detail set state =#{stateId} where sales_order_id = #{salesOrderId}")
    int updateStatesById(@Param("stateId") Long stateId, @Param("salesOrderId") Long salesOrderId);
}
